﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SlotJoint.CApSlotJointCurveValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.SlotJoint;

public class CApSlotJointCurveValidator : ITxValidator
{
  private MessageTypes _errorType;
  private string _detailedErrorMessage;

  public CApSlotJointCurveValidator() => this.ShowTooltip = true;

  public MessageTypes ErrorType
  {
    get => this._errorType;
    set => this._errorType = value;
  }

  public string DetailedErrorMessage
  {
    get => this._detailedErrorMessage;
    set => this._detailedErrorMessage = value;
  }

  public bool ShowTooltip { get; set; }

  public ITxObject GetObject(string objName)
  {
    ITxObject itxObject1 = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (!string.IsNullOrEmpty(objName))
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(objName);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      foreach (ITxObject itxObject2 in (Collection<ITxObject>) txObjectList)
      {
        if (this.IsValidObject(itxObject2, out string _))
        {
          itxObject1 = itxObject2;
          break;
        }
      }
    }
    return itxObject1;
  }

  public ITxObject GetObjectWithoutValidation(string objName)
  {
    ITxObject withoutValidation = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (!string.IsNullOrEmpty(objName))
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(objName);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
      withoutValidation = ((Collection<ITxObject>) txObjectList)[0];
    return withoutValidation;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = false;
    this._detailedErrorMessage = string.Empty;
    this._errorType = MessageTypes.None;
    errorMessage = (string) null;
    switch (obj)
    {
      case null:
        errorMessage = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.InvalidCurveObject;
        break;
      case TxCurve _:
      case TxArc _:
      case TxPolyline _:
      case TxLine _:
      case Tx1DimensionalGeometry _:
        if (this.IsCurveValid(obj as ITx1DimensionalGeometry))
        {
          flag = true;
          break;
        }
        errorMessage = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.InvalidCurveObject;
        break;
      default:
        errorMessage = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.InvalidCurveObject;
        break;
    }
    if (!this.ShowTooltip)
      errorMessage = string.Empty;
    return flag;
  }

  private bool IsCurveValid(ITx1DimensionalGeometry curve)
  {
    bool flag = false;
    if (curve is ITxDisplayableObject && (curve as ITxDisplayableObject).Visibility != null)
      this._detailedErrorMessage = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.InvalidCurveBlanked;
    else if (!CApSlotJointUtils.IsCurveValid(curve))
      this._detailedErrorMessage = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.InvalidCurve;
    else if (CApSlotJointUtils.IsCurveClosed(curve))
      this._detailedErrorMessage = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.InvalidCurveClosed;
    else if (!CApSlotJointUtils.IsCurvePlanar(curve))
      this._detailedErrorMessage = DnProcessSimulateCommands.SlotJoint.Resources.StringTable.InvalidCurvePlanar;
    else
      flag = true;
    if (!flag)
      this._errorType = MessageTypes.Warning;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    return this.IsValidObject(this.GetObjectWithoutValidation(text), out errorMessage);
  }
}
